"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#文 件 名:      SecurityUserIamFaceAuthApi.py
#文件说明:      face关公共AW
#作   者:
#生成日期:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import keyword
from aw.Useriam.AuthWidget import SecurityUserIamAuthWidgetCommon


@keyword
def setFace(oh_device):
    """
    #======================================================================
    #   @Method:           setFace(oh_device)
    #   @Precondition:
    #   @Func:             预置人脸
    #   @Param:
    #   @Example:
    #======================================================================
    """
    SecurityUserIamAuthWidgetCommon.enterhapseeting(oh_device)
    CommonOH.touchByText(oh_device, "预置人脸")

@keyword
def faceAuth(oh_device, face_type=0):
    """
    #======================================================================
    #   @Method:           faceAuth(oh_device, face_type)
    #   @Precondition:
    #   @Func:             人脸认证
    #   @Param:            face_type:人脸认证，0:使用正确人脸认证，1:使用错误人脸认证，2:取消认证
    #   @Example:
    #======================================================================
    """
    if face_type == 0:
        CommonOH.touchByText(oh_device, "取消")
    elif face_type == 1:
        CommonOH.touchByText(oh_device, "使用密码")
    else:
        print("您输入的type值错误，请传入正确的type值")
        return False

@keyword
def retryfaceAuth(oh_device):
    """
        #======================================================================
        #   @Method:           retryfaceAuth(oh_device, face_type)
        #   @Precondition:
        #   @Func:             人脸认证重试
        #   @Param:            face_type:人脸认证，0:使用正确人脸认证，1:使用错误人脸认证，2:取消认证
        #   @Example:
        #======================================================================
        """
    CommonOH.touchByText(oh_device, "未识别成功，点击此处重试")

@keyword
def unclockface(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           unclockface(oh_device, pin,pin_type)
    #   @Precondition:
    #   @Func:             解除人脸锁定
    #   @Param:            pin:设置的pin码
    #   @Param:            pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    CommonOH.touchByText(oh_device, "使用密码")
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False

@keyword
def switchpin(oh_device, pin, pin_type=0):
    """
        #======================================================================
        #   @Method:           switchpin(oh_device, pin,pin_type)
        #   @Precondition:
        #   @Func:             切换口令认证
        #   @Param:            pin:设置的pin码
        #   @Param:            pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
        #   @Example:
        #======================================================================
        """
    CommonOH.touchByText(oh_device, "使用密码")
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False

@keyword
def switchpincancel(oh_device):
    """
        #======================================================================
        #   @Method:           switchpincancel(oh_device)
        #   @Precondition:
        #   @Func:             切换口令认证，取消口令认证
        #   @Param:
        #   @Param:
        #   @Example:
        #======================================================================
        """
    CommonOH.touchByText(oh_device, "使用密码")
    CommonOH.touchByText(oh_device, "取消")
